package com.tuanzi.loan.business.service.family.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.entity.family.ExternalPhoneRecord;
import com.tuanzi.loan.business.repository.family.ExternalPhoneRecordRepository;
import com.tuanzi.loan.business.service.family.ExternalPhoneRecordService;
import com.tuanzi.loan.core.repository.JPAAuditRepository;
import com.tuanzi.loan.core.service.BaseAuditServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.family.ExternalShowSearchRequest;
import com.tuanzi.loan.vo.response.family.ExternalShowSearchResponse;
/**
 * 
 * @author Xumiaohang 2017/11/17
 *
 */
@Service
@Transactional
public class ExternalPhoneRecordServiceImpl extends BaseAuditServiceImpl<ExternalPhoneRecord, Long> implements ExternalPhoneRecordService {

	@Autowired
	private ExternalPhoneRecordRepository externalPhoneRecordRepository;
	

	@Override
	protected JPAAuditRepository<ExternalPhoneRecord, Long> getRepository() {
		return externalPhoneRecordRepository;
	}

	//根据手机号码检查重复的记录
	@Override
	public List<String> repeatCheck(List<String> list) {
		return externalPhoneRecordRepository.repeatCheck(list);
	}

	@Override
	public Page<ExternalShowSearchResponse> list(
			PageSearcher<ExternalShowSearchRequest> pageSearcher) {
		Page<ExternalShowSearchResponse> page = externalPhoneRecordRepository.list(
				pageSearcher.getSearchCondition(), pageSearcher.getPageable());
		List<ExternalShowSearchResponse> list = page.getContent();
		if(list != null) {
			for(ExternalShowSearchResponse model : list) {
				String mobnum = model.getUserId();
				model.setUserId(mobnum.substring(0, 3)+"****"+mobnum.substring(7, 11));
			}
		}
		return page;
	}

	@Override
	public List<String> findSource() {
		return externalPhoneRecordRepository.findSource();
	}


}
